package com.imageim.yimirror.ui.fragment;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.imageim.yimirror.R;
import com.imageim.yimirror.base.BaseFragment;
import com.imageim.yimirror.base.Constants;
import com.imageim.yimirror.bean.IntelligenRecommendBean;
import com.imageim.yimirror.common.event.EventCode;
import com.imageim.yimirror.common.event.EventMessage;
import com.imageim.yimirror.common.network.constants.NetConstants;
import com.imageim.yimirror.common.ui.GlideUtils;
import com.imageim.yimirror.common.util.AnimUtil;
import com.imageim.yimirror.common.util.ClickUtil;
import com.imageim.yimirror.common.util.UserUtil;
import com.imageim.yimirror.net.NetPresenterImpl;
import com.imageim.yimirror.net.NetView;
import com.imageim.yimirror.ui.adapter.ExpandListAdapter;
import com.imageim.yimirror.ui.adapter.RecommendPhotoAdapter;
import com.imageim.yimirror.ui.widght.EmptyView;
import com.imageim.yimirror.ui.widght.LoadingView;
import com.makeramen.roundedimageview.RoundedImageView;
import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.EventBus;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Yuaihen.
 * on 2018/7/6
 * 智能推荐Fragment
 */
public class IntelligenRecommendFragment extends BaseFragment implements ExpandableListView.OnChildClickListener, RecommendPhotoAdapter.OnItemClickListener, ExpandableListView.OnGroupClickListener, NetView, OnRefreshListener, EmptyView.OnFinishBtnClickListener {

    private static final String TAG = "RecommendFragment";
    @BindView(R.id.rv_photo)
    RecyclerView mRvPhoto;
    @BindView(R.id.expand_list_occasion)
    ExpandableListView mExpandLeftListView;
    @BindView(R.id.expand_list_color)
    ExpandableListView mExpandRightListView;
    @BindView(R.id.iv_main_photo)
    RoundedImageView mIvMainPhoto;
    @BindView(R.id.tv_match)
    TextView mTvMatch;
    @BindView(R.id.iv_match1)
    ImageView mIvMatch1;
    @BindView(R.id.iv_match2)
    ImageView mIvMatch2;
    @BindView(R.id.iv_match3)
    ImageView mIvMatch3;
    @BindView(R.id.ll_match)
    LinearLayout mLlMatch;
    @BindView(R.id.tv_like)
    TextView mTvLike;
    @BindView(R.id.loading_view)
    LoadingView mLoadingView;
    @BindView(R.id.smart_refresh)
    SmartRefreshLayout mSmartRefresh;
    @BindView(R.id.tv_suit_occasion)
    TextView mTvSuitOccasion;
    @BindView(R.id.empty_view)
    EmptyView mEmptyView;
    private RecommendPhotoAdapter mRecommendPhotoAdapter;
    //    private String[] occasionGroupStrings = {"全部场合"};
    private String[] occasionGroupStrings;
    //    private String[] occasionItemStrings = {"全部场合", "轻松职场", "正式职场", "都市休闲", "海滨度假", "日间社交", "晚间社交", "运动休闲", "时尚聚会"};
    private String[] occasionItemStrings;
    //    private String[] colorGroupStrings = {"全部颜色"};
    private String[] colorGroupStrings;
    //    private String[] colorItemStrings = {"全部颜色", "黑色", "白色", "暖色系", "冷色系"};
    private String[] colorItemStrings;
    private ExpandListAdapter mOccasionAdapter;
    private ExpandListAdapter mColorAdapter;
    private List<IntelligenRecommendBean.ClothingsBean> mClothingsList;
    private float mDensity;
    private int mHiddenViewMeasuredHeight;
    private NetPresenterImpl mNetPresenter;
    private HashMap<String, String> map;
    private List<IntelligenRecommendBean.OccasionsBean> mOccasionsList;
    private List<IntelligenRecommendBean.ColorLabelsBean> mColorsList;
    private boolean[] mColorIsSelect;
    private boolean[] mOccasionIsSelect;
    private int currentOccasionId = 0;
    private int currentColorId = 0;
    private int currentItemPosition = 0;
    private int lastSelectOccasionPosition;
    private int lastSelectColorPosition;
    private boolean isRefresh;
    private ImageView[] mIvMatchViews;
    private List<IntelligenRecommendBean.ClothingsBean.accessoryListBean> mAccessoryList;
    private HashMap<String, String> mCollectMap;
    private HashMap<String, String> mCancelCollectMap;

    @Override
    protected int getLayoutId() {
        return R.layout.intelligen_recommend_fragment;
    }


    @Override
    protected void initListener() {
        mIvMatchViews = new ImageView[]{mIvMatch1, mIvMatch2, mIvMatch3};

        //搭配区域布局的高度 700dp
        mDensity = getResources().getDisplayMetrics().density;
        mHiddenViewMeasuredHeight = (int) (mDensity * 700 + 0.5);

        mOccasionAdapter = new ExpandListAdapter(occasionGroupStrings, occasionItemStrings);
        mColorAdapter = new ExpandListAdapter(colorGroupStrings, colorItemStrings);
        mExpandLeftListView.setAdapter(mOccasionAdapter);
        mExpandRightListView.setAdapter(mColorAdapter);
        //        mExpandLeftListView.setChildDivider(new ColorDrawable(getResources().getColor(R.color.cus_gray)));
        //        mExpandRightListView.setChildDivider(new ColorDrawable(getResources().getColor(android.R.color.darker_gray)));

        //设置子选项点击监听事件
        mExpandLeftListView.setOnGroupClickListener(this);
        mExpandRightListView.setOnGroupClickListener(this);
        mExpandLeftListView.setOnChildClickListener(this);
        mExpandRightListView.setOnChildClickListener(this);
        //设置展开关闭监听事件
        mExpandLeftListView.setOnGroupExpandListener(groupPosition -> mExpandLeftListView.setSelected(true));
        mExpandLeftListView.setOnGroupCollapseListener(groupPosition -> mExpandLeftListView.setSelected(false));
        mExpandRightListView.setOnGroupExpandListener(groupPosition -> mExpandRightListView.setSelected(true));
        mExpandRightListView.setOnGroupCollapseListener(groupPosition -> mExpandRightListView.setSelected(false));


        mRvPhoto.setLayoutManager(new LinearLayoutManager(mContext));
        mRecommendPhotoAdapter = new RecommendPhotoAdapter(mContext, mClothingsList);
        mRvPhoto.setAdapter(mRecommendPhotoAdapter);
        mRecommendPhotoAdapter.setOnItemClickListener(this);

        //下拉刷新
        mSmartRefresh.setRefreshHeader(new MaterialHeader(mContext));
        mSmartRefresh.setOnRefreshListener(this);

        mEmptyView.setOnFinishBtnClickListener(this);
    }


    @Override
    protected void initData() {
        mNetPresenter = new NetPresenterImpl(this);
        getClothingResult(currentOccasionId, currentColorId, false);
    }


    /**
     * 点击一个展开菜单的时候关闭另外一个菜单
     */
    @Override
    public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
        if (parent.getId() == R.id.expand_list_occasion) {
            mExpandRightListView.collapseGroup(0);
            logD(TAG, "左边");
        } else if (parent.getId() == R.id.expand_list_color) {
            mExpandLeftListView.collapseGroup(0);
            logD(TAG, "右边");
        }
        return false;
    }

    /**
     * 关闭折叠菜单
     */
    private void closeExpandList() {
        if (mExpandLeftListView != null) {
            mExpandLeftListView.collapseGroup(0);
        }
        if (mExpandRightListView != null) {
            mExpandRightListView.collapseGroup(0);
        }

    }


    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        if (parent.getId() == R.id.expand_list_occasion) {
            Log.d(TAG, "onChildClick: groupPosition= " + groupPosition + " childPosition= " + childPosition);
            //item设置为选中  并且将group的title更改为item的title  需要在adapter里面设置 ExpandLeftListView展开或者关闭会刷新
            String child = (String) parent.getExpandableListAdapter().getChild(groupPosition, childPosition);
            mOccasionAdapter.setGroupTitle(child);
            mOccasionIsSelect[lastSelectOccasionPosition] = false;
            mOccasionIsSelect[childPosition] = true;
            lastSelectOccasionPosition = childPosition;
            mExpandLeftListView.collapseGroup(0);
            getClothingResult(mOccasionsList.get(childPosition).getOccasionId(), currentColorId, true);
            return true;
        } else if (parent.getId() == R.id.expand_list_color) {
            String child = (String) parent.getExpandableListAdapter().getChild(groupPosition, childPosition);
            mColorAdapter.setGroupTitle(child);
            mColorIsSelect[lastSelectColorPosition] = false;
            mColorIsSelect[childPosition] = true;
            lastSelectColorPosition = childPosition;
            mExpandRightListView.collapseGroup(0);
            getClothingResult(currentOccasionId, mColorsList.get(childPosition).getLabelId(), true);
            return true;
        }
        return false;
    }


    private static final int MSG_GET_CLOTHING = 0x001;
    private static final int MSG_GET_CLOTHING_AGAIN = 0x002;
    private static final int MSG_ADD_COLLECT = 0x003;
    private static final int MSG_CANCEL_COLLECT = 0x004;


    /**
     * 获取服装信息
     *
     * @param occasionId 场合ID    只能查询单个场合ID
     * @param colorId    colorId   只能查询单个ColorID
     * @param isAgainGet 是否重新获取数据  不更新场合List和ColorList
     */
    private void getClothingResult(final int occasionId, final int colorId, boolean isAgainGet) {
        currentItemPosition = 0;
        currentOccasionId = occasionId;
        currentColorId = colorId;

        if (map == null) {
            map = new HashMap<>(8);
        }
        map.put(Constants.PHOTO_NO, UserUtil.getPhotoNo());
        map.put(Constants.OCCASIONIDS, currentOccasionId + "");
        map.put(Constants.COLOR_LABEL_IDS, currentColorId + "");

        //        //temp
        //        map.put(Constants.PHOTO_NO, "CN201812042048016FYT");
        //        map.put("mac", "AC83F3B47D82");
        //        map.put("token", "2d559331d31044ea81b19da9bc42078c1544099515778");
        if (isAgainGet) {
            mNetPresenter.getObject(mContext, NetConstants.URL.GET_RECOMMEND_CLOTHING, map, IntelligenRecommendBean.class, MSG_GET_CLOTHING_AGAIN);
        } else {
            mNetPresenter.getObject(mContext, NetConstants.URL.GET_RECOMMEND_CLOTHING, map, IntelligenRecommendBean.class, MSG_GET_CLOTHING);
        }
    }


    /**
     * 收藏和取消收藏
     */
    private void likeOrCancel(int position) {
        if (mClothingsList == null || mClothingsList.size() <= 0) {
            return;
        }

        //  0未收藏   1收藏
        int collectFlag = mClothingsList.get(position).getCollectFlag();
        String clothingCode = mClothingsList.get(position).getClothingCode();
        if (!TextUtils.isEmpty(clothingCode)) {
            if (collectFlag == 1) {
                //已经收藏  取消收藏
                cancelCollect(clothingCode);
            } else {
                //没有收藏  添加收藏
                addCollect(clothingCode);
            }
        }

    }


    /**
     * 添加收藏
     *
     * @param clothingCode 服装编码
     */
    private void addCollect(String clothingCode) {
        if (mCollectMap == null) {
            mCollectMap = new HashMap<>(4);
        }
        mCollectMap.put(Constants.USER_ID, UserUtil.getUserId());
        mCollectMap.put(Constants.CLOTHING_CODE, clothingCode);

        //temp
        //        mCollectMap.put("mac", "AC83F3B47D82");
        //        mCollectMap.put("userId", "BC20181206171718ibsQ");
        //        mCollectMap.put("token", "2d559331d31044ea81b19da9bc42078c1544099515778");
        mNetPresenter.getObject(mContext, NetConstants.URL.COLLECT_CLOTHING, mCollectMap, MSG_ADD_COLLECT);
    }


    /**
     * 取消收藏
     *
     * @param clothingCode 服装编码
     */
    private void cancelCollect(String clothingCode) {
        if (mCancelCollectMap == null) {
            mCancelCollectMap = new HashMap<>(4);
        }
        mCancelCollectMap.put(Constants.USER_ID, UserUtil.getUserId());
        mCancelCollectMap.put(Constants.CLOTHING_CODE, clothingCode);

        //temp
        //        mCancelCollectMap.put("mac", "AC83F3B47D82");
        //        mCancelCollectMap.put("userId", "BC20181206171718ibsQ");
        //        mCancelCollectMap.put("token", "2d559331d31044ea81b19da9bc42078c1544099515778");
        mNetPresenter.getObject(mContext, NetConstants.URL.CANCEL_COLLECT, mCancelCollectMap, MSG_CANCEL_COLLECT);
    }


    /**
     * 设置主图以及配饰信息
     *
     * @param position item的位置
     */
    private void setMainAndMatchData(int position) {
        if (mClothingsList == null || mClothingsList.size() <= 0) {
            return;
        }

        //切换小图时关闭搭配区域以及折叠菜单
        if (mLlMatch.getVisibility() == View.VISIBLE) {
            closeMatchArea();
        }

        closeExpandList();

        //设置数据
        IntelligenRecommendBean.ClothingsBean clothingsBean = mClothingsList.get(position);
        if (clothingsBean != null) {
            String clothingUrl = clothingsBean.getClothingUrl();
            if (!TextUtils.isEmpty(clothingUrl)) {
                GlideUtils.display(mIvMainPhoto, clothingUrl);
            }

            //是否收藏过 0未收藏 1收藏
            int collectFlag = clothingsBean.getCollectFlag();
            if (collectFlag == 1) {
                mTvLike.setSelected(true);
                mTvLike.setText("取消");
            } else {
                mTvLike.setSelected(false);
                mTvLike.setText("喜欢");
            }

            //搭配信息
            mAccessoryList = Optional.ofNullable(clothingsBean.getAccessoryList())
                    .orElse(new ArrayList<>());
            if (mAccessoryList.size() > 0) {
                mTvMatch.setVisibility(View.VISIBLE);
                for (int i = 0; i < mAccessoryList.size(); i++) {
                    if (i >= mIvMatchViews.length) {
                        return;
                    }
                    String matchUrl = mAccessoryList.get(i).getClothingUrl();
                    if (!TextUtils.isEmpty(matchUrl)) {
                        GlideUtils.display(mIvMatchViews[i], matchUrl);
                    }
                }
            } else {
                mTvMatch.setVisibility(View.GONE);
            }

            //设置适用场合
            String occasionNames = clothingsBean.getOccasionNames();
            if (!TextUtils.isEmpty(occasionNames)) {
                mTvSuitOccasion.setVisibility(View.VISIBLE);
                String[] suitOccasionNames = occasionNames.split(",");
                StringBuilder stringBuilder = new StringBuilder();
                for (int i = 0; i < suitOccasionNames.length; i++) {
                    stringBuilder.append(suitOccasionNames[i]);
                    if (i != suitOccasionNames.length - 1) {
                        stringBuilder.append("、");
                    }
                }
                mTvSuitOccasion.setText(MessageFormat.format("适合场合：{0}", stringBuilder.toString()));
            } else {
                mTvSuitOccasion.setVisibility(View.GONE);
            }

        }
    }


    private void showLoading() {
        if (mLoadingView != null) {
            mLoadingView.setVisibility(View.VISIBLE);
        }
    }

    private void hideLoading() {
        if (mLoadingView != null) {
            mLoadingView.setVisibility(View.GONE);
        }
    }


    /**
     * 左侧Rv item点击重新设置主图和配饰
     */
    @Override
    public void onClickPhoto(int position) {
        if (currentItemPosition != position) {
            currentItemPosition = position;
            setMainAndMatchData(currentItemPosition);
        }

    }


    @OnClick({R.id.tv_match, R.id.tv_like})
    public void onViewClicked(View v) {
        switch (v.getId()) {
            case R.id.tv_match:
                //展开搭配区域
                if (mLlMatch.getVisibility() == View.GONE) {
                    openMatchArea();
                } else {
                    closeMatchArea();
                }
                break;
            case R.id.tv_like:
                //收藏或取消收藏
                if (ClickUtil.isValidClick()) {
                    likeOrCancel(currentItemPosition);
                }
                break;
            default:
                break;
        }
    }


    /**
     * 从上往下滑动显示搭配区域
     * 如果没有配饰不操作
     */
    private void openMatchArea() {
        if (mAccessoryList != null && mAccessoryList.size() > 0) {
            mTvMatch.setSelected(true);
            AnimUtil.slideShowArea(mLlMatch, mHiddenViewMeasuredHeight, 500);
        }
    }

    /**
     * 从下往上滑动隐藏搭配区域
     * 如果没有配饰不操作
     */
    private void closeMatchArea() {
        if (mAccessoryList != null && mAccessoryList.size() > 0) {
            mTvMatch.setSelected(false);
            AnimUtil.slideHideArea(mLlMatch, mTvMatch, 500);
        }
    }

    @Override
    public void onLoadPre(int msgCode) {
        showLoading();
    }

    @Override
    public void onLoadSuccess(Object result, int msgCode) {
        hideLoading();
        if (msgCode == MSG_GET_CLOTHING || msgCode == MSG_GET_CLOTHING_AGAIN) {
            if (isRefresh) {
                mSmartRefresh.finishRefresh();
                isRefresh = false;
            }
            setData(result, msgCode);
        } else if (msgCode == MSG_ADD_COLLECT) {
            setCollectStatus(true);
            updateCollect();
        } else if (msgCode == MSG_CANCEL_COLLECT) {
            setCollectStatus(false);
            updateCollect();
        }
    }

    /**
     * 改变收藏按钮的选中 以及
     *
     * @param collect true收藏  false取消收藏
     */
    private void setCollectStatus(boolean collect) {
        if (collect) {
            mTvLike.setText("取消");
            mTvLike.setSelected(true);
            mClothingsList.get(currentItemPosition).setCollectFlag(1);
        } else {
            mTvLike.setText("喜欢");
            mTvLike.setSelected(false);
            mClothingsList.get(currentItemPosition).setCollectFlag(0);
        }
    }


    @Override
    public void onLoadFail(int errorCode, String errorMsg, int msgCode) {
        hideLoading();
        showEmptyView(true);
        if (msgCode == MSG_GET_CLOTHING || msgCode == MSG_GET_CLOTHING_AGAIN) {
            if (isRefresh) {
                mSmartRefresh.finishRefresh();
                isRefresh = false;
            }
        }
        toast(errorCode + errorMsg);
    }


    /**
     * 设置Adapter 场合颜色和配饰信息
     *
     * @param result  返回的bean
     * @param msgCode 消息码对应的请求
     */
    private void setData(Object result, int msgCode) {
        IntelligenRecommendBean bean = (IntelligenRecommendBean) result;

        //服装信息
        mClothingsList = Optional.ofNullable(bean)
                .flatMap(b -> Optional.ofNullable(b.getClothings()))
                .orElse(new ArrayList<>());

        //根据场合和颜色ID来查询的时候不重新刷新List
        if (msgCode == MSG_GET_CLOTHING) {
            //场合列表
            mOccasionsList = Optional.ofNullable(bean)
                    .flatMap(b -> Optional.ofNullable(b.getOccasions()))
                    .orElse(new ArrayList<>());

            //颜色列表
            mColorsList = Optional.ofNullable(bean)
                    .flatMap(b -> Optional.ofNullable(b.getColorLabels()))
                    .orElse(new ArrayList<>());

            setOccasion();
            setColor();
        }

        setAdapter(0);

    }

    /**
     * 设置服装Adapter
     */
    private void setAdapter(int position) {
        if (mClothingsList.size() > 0) {
            hideEmptyView();
            showLikeAndMatchArea();
            mClothingsList.get(0).setChecked(true);
            mRecommendPhotoAdapter.update(mClothingsList);
            if (mRvPhoto != null && mRvPhoto.getChildCount() > 0) {
                mRvPhoto.scrollToPosition(0);
            }
            setMainAndMatchData(position);
        } else {
            showEmptyView(false);
            mRecommendPhotoAdapter.update(mClothingsList);
            mIvMainPhoto.setImageResource(R.drawable.ic_no_main_photo);
            hideLikeAndMatchArea();
        }
    }


    /**
     * 设置场合List
     */
    private void setOccasion() {
        if (mOccasionsList.size() > 0) {
            occasionItemStrings = new String[mOccasionsList.size()];
            occasionGroupStrings = new String[1];
            mOccasionIsSelect = new boolean[mOccasionsList.size()];

            for (int i = 0; i < mOccasionsList.size(); i++) {
                IntelligenRecommendBean.OccasionsBean occasionsBean = mOccasionsList.get(i);
                if (i == 0) {
                    occasionGroupStrings[i] = occasionsBean.getOccasionName();
                }

                String occasionNameAndNum = MessageFormat.format("{0}({1})", occasionsBean.getOccasionName(), occasionsBean.getNum());
                occasionItemStrings[i] = occasionNameAndNum;
                mOccasionIsSelect[i] = occasionsBean.getIfChecked();
            }
            mOccasionAdapter.updateAdapter(occasionGroupStrings, occasionItemStrings, mOccasionIsSelect);
        }
    }


    /**
     * 设置颜色List
     */
    private void setColor() {
        if (mColorsList.size() > 0) {
            colorItemStrings = new String[mColorsList.size()];
            colorGroupStrings = new String[1];
            mColorIsSelect = new boolean[mColorsList.size()];
            for (int i = 0; i < mColorsList.size(); i++) {
                IntelligenRecommendBean.ColorLabelsBean colorLabelsBean = mColorsList.get(i);
                if (i == 0) {
                    colorGroupStrings[i] = colorLabelsBean.getLabelName();
                }

                String colorNameAndNum = MessageFormat.format("{0}({1})", colorLabelsBean.getLabelName(), colorLabelsBean.getNum());
                colorItemStrings[i] = colorNameAndNum;
                mColorIsSelect[i] = colorLabelsBean.getIfChecked();
            }
            mColorAdapter.updateAdapter(colorGroupStrings, colorItemStrings, mColorIsSelect);
        }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mNetPresenter != null) {
            mNetPresenter.onDestroy();
        }
    }


    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (mNetPresenter != null) {
            isRefresh = true;
            getClothingResult(0, 0, false);
        }
    }

    /**
     * 显示收藏和搭配区域
     */
    private void showLikeAndMatchArea() {
        mTvLike.setVisibility(View.VISIBLE);
        mTvMatch.setVisibility(View.VISIBLE);
    }


    private void hideLikeAndMatchArea() {
        mTvLike.setVisibility(View.GONE);
        mTvMatch.setVisibility(View.GONE);
    }


    @Override
    public void onEventMainThread(EventMessage event) {
        super.onEventMainThread(event);
        if (event.getCode() == EventCode.CODE_REFRESH_ADAPTER) {
            String clothingCode = (String) event.getValue();
            updateSelectState(clothingCode);
        }
    }

    /**
     * 我的收藏删除之后刷新选中状态
     *
     * @param clothingCode 衣服编号
     */
    private void updateSelectState(String clothingCode) {
        if (mClothingsList == null || mClothingsList.size() <= 0) {
            return;
        }

        for (int i = 0; i < mClothingsList.size(); i++) {
            if (clothingCode.equals(mClothingsList.get(i).getClothingCode())) {
                mClothingsList.get(i).setCollectFlag(0);
                break;
            }
        }
        mRecommendPhotoAdapter.update(mClothingsList);
        setMainAndMatchData(0);
    }

    private void updateCollect() {
        EventBus.getDefault().post(new EventMessage(EventCode.CODE_REFRESH_WITH_COLLECT_PAGE, null));
    }

    /**
     * 显示空布局
     *
     * @param isError 是网络错误还是数据为空
     */
    private void showEmptyView(boolean isError) {
        if (mEmptyView != null) {
            mEmptyView.setVisibility(View.VISIBLE);
            //网络错误显示刷新按钮
            if (isError) {
                mEmptyView.setErrorImg(R.drawable.ic_error);
                mEmptyView.setErrorContent("数据获取失败，请重试~");
                mEmptyView.setBtnVisiable(true);
            } else {
                mEmptyView.setErrorImg(R.drawable.ic_no_result);
                mEmptyView.setErrorContent("暂无服装数据~");
                mEmptyView.setBtnVisiable(false);
            }
        }
    }

    private void hideEmptyView() {
        if (mEmptyView != null) {
            mEmptyView.setVisibility(View.GONE);
        }
    }

    /**
     * 点击空布局的刷新按钮
     */
    @Override
    public void onFinishBtnClick() {
        if (mNetPresenter != null) {
            isRefresh = true;
            getClothingResult(0, 0, true);
        }
    }
}
